﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using ZyGames.DZPocker.Model;
using ZyGames.Framework.Game.Message;
using ZyGames.Framework.Game.Model;

namespace ZyGames.DZPocker.Script.CsScript.Com
{
	public class MyBroadcastService : BroadcastService
	{
		/// <summary>
		/// 发送
		/// </summary>
		/// <param name="content"></param>
		/// <param name="times">发送次数</param>
		/// <param name="secondInvertal">间隔发送</param>
		public static void SendTimer(string content, int times, int secondInvertal)
		{
			var broadcastService = new MyBroadcastService(null);
			var msg = broadcastService.Create(NoticeType.System, content);
			string startTime = DateTime.Now.ToString("HH:mm:ss");
			string endTime = DateTime.Now.AddSeconds(times * secondInvertal).ToString("HH:mm:ss");
			broadcastService.SendTimer(msg, startTime, endTime, true, secondInvertal);
		}

		/// <summary>
		/// 
		/// </summary>
		/// <param name="content"></param>
		public static void Send(string content)
		{
			var broadcastService = new MyBroadcastService(null);
			var msg = broadcastService.Create(NoticeType.System, content);
			broadcastService.Send(msg);
		}

		private readonly GameUser _user;
		public const int MaxCount = 50;
		private SensitiveWordService _wordServer;

		public MyBroadcastService(GameUser user)
		{
			_user = user;
			_wordServer = new SensitiveWordService();//敏感词管理类
		}
		protected override void SetVersionId(int versionId)
		{
			if (_user != null)
			{
				//设置读取广播的位置，版本号是全局自增的
				_user.Property.BroadcastVesion = versionId;
			}
		}

		public bool HasMessage()
		{
			//判断是否有新的广播
			return HasMessage(_user.Property.BroadcastVesion);
		}

		public List<NoticeMessage> GetMessages()
		{
			//获取广播信息列表
			return GetMessages(_user.Property.BroadcastVesion, MaxCount);
		}

		protected override string FilterMessage(string message)
		{
			//过滤敏感词，默认以*号替换
			return _wordServer.Filter(message);
		}
	}

}
